class Admin::CategoriesController< ApplicationController

  layout "posts"

  before_filter :is_admin

  def index
    @categories = Category.find(:all)
  end

  def edit
    @category = Category.find_by_id(params[:id])
    @user_level_rules = UserLevelRule.find(:all)
  end

  def update
    @category = Category.find(params[:id])
    if @category.update_attributes(params[:category])
      redirect_to show_category_posts_path(@category.id)
    else
      render :template => "/admin/categories/edit"
    end
  end

  def destroy
    @category = Category.find_by_id(params[:id])
    @category.destroy
    redirect_to category_control_panel_path
  end

  def new
    @categories = Category.find(:all)
    @category = Category.new
    @rules = UserLevelRule.find(:all)
  end

  def create
    @category = Category.new(params[:category])
		if @category.save
      redirect_to category_control_panel_path
		else
			render :template => "admin/cat/new"
		end
  end

  private
  def is_admin
    return true if User.is_admin(session[:user_id])
    session[:denied_path] = request.request_uri
    redirect_to denied_path
  end

end